//
//  HomeViewController.m
//  Hxcsfw
//
//  Created by 企友软mac on 2017/10/25.
//  Copyright © 2017年 企友软mac. All rights reserved.
//

#import "HomeViewController.h"
#import "STSegmentView.h"
#import "NewHotViewController.h"
//#import "ReportViewController.h"
//#import "InvoiceViewController.h"
#import "SpokenViewController.h"
#import "RegulationViewController.h"
#import "WDXXViewController.h"
#import "SearchViewController.h"
#import "SchoolViewController.h"
#import "GifView.h"
#import "WWebViewController.h"
#import "LoginViewController.h"
#import "HAnswerViewController.h"

@interface HomeViewController ()<UIScrollViewDelegate,STSegmentViewDelegate,NewHotControllerDelegate>
{
    GifView *dataView;
    UIButton *rightBtn;
    UIButton *leftBtn;
    UIImageView *NavimgView;
    UIView *NavSearchView;
    UIView *ScreenView;
    UILabel *NavSearchLb;
}
@property (nonatomic,strong) UIScrollView *homeScrollView;
@property (nonatomic,strong) STSegmentView *titScrollView;
@property (nonatomic ,strong) NSString *strId;//分享id
@property (nonatomic ,strong) NSString *strKhdupsj;//客户端更新时间
@property (nonatomic ,strong) NSString *strUpsj;//服务器更新时间
@property (nonatomic,strong) NSMutableArray *hotArray;

//@property (nonatomic,strong) STSegmentView *hotView;
//@property (nonatomic,strong) STSegmentView *reportView;
//@property (nonatomic,strong) STSegmentView *invoiceView;
//@property (nonatomic,strong) STSegmentView *spokenView;
//@property (nonatomic,strong) STSegmentView *regulationView;

@end

@implementation HomeViewController

- (NSMutableArray *)hotArray {
    if (_hotArray == nil) {
        _hotArray = [NSMutableArray array];
    }
    return _hotArray;
}

//每次到首页做服务状态的检测
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    // 左上角“掌税通”图
    NavimgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"zst_text"]];
    NavimgView.frame = CGRectMake(15,12,65, 20);
    [self.navigationController.navigationBar addSubview:NavimgView];
    
    // 中间的搜索栏View
    NavSearchView = [[UIView alloc]initWithFrame:CGRectMake(95, 10, WSCREENH_WIDTH - 90 - 90 - 10, 26)];
    NavSearchView.backgroundColor = [UIColor colorWithRed:0.17 green:0.28 blue:0.82 alpha:1];

    NavSearchView.layer.masksToBounds = YES;
    NavSearchView.layer.cornerRadius = 13;
    // 文字lb
    NavSearchLb = [[UILabel alloc]initWithFrame:CGRectMake(15, 6, WSCREENH_WIDTH - 90 - 90 - 10 - 5 - 20 - 8 - 5, 14)];
    NavSearchLb.text = @"抄税清卡  |  开票升级";
    NavSearchLb.font = [UIFont systemFontOfSize:15];
    NavSearchLb.textColor = WColorFromHexToRGB(0xd6e9f7);
    [NavSearchView addSubview:NavSearchLb];

    [self SearchVCDataRequest];
    
    //放大镜
    UIImageView *NavFdjView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"search_new"]];
    NavFdjView.frame = CGRectMake(WSCREENH_WIDTH - 90 - 90 - 22 - 10, 7, 12, 12);
    [NavSearchView addSubview:NavFdjView];

    //按钮
    UIButton *NavBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    NavBtn.frame = CGRectMake(0, 0, WSCREENH_WIDTH - 90 - 90, 26);
    NavBtn.backgroundColor = [UIColor clearColor];
    NavBtn.layer.masksToBounds = YES;
    NavBtn.layer.cornerRadius = 13;
    [NavBtn addTarget:self action:@selector(NavBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [NavSearchView addSubview:NavBtn];
    [self.navigationController.navigationBar addSubview:NavSearchView];

    // 本地gif图片（旋转菊花）  shouye_checking_icon
    NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"shouye_loading" ofType:@"gif"]];
    
    dataView = [[GifView alloc] initWithFrame:CGRectMake(WSCREENH_WIDTH-48, 7, 25, 25) data:localData];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:dataView];

    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc] initWithCustomView:dataView],[[UIBarButtonItem alloc] initWithCustomView:leftBtn]];


    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(YJJCDataRequest) name:@"ServiceExamineRefresh" object:nil];

//    [self YJJCDataRequest];
    //消息红点的请求
    [self Message];
}

- (void)NavBtnClick {
    WLog(@"导航搜索");
    SearchViewController *searchVC = [[SearchViewController alloc]init];
    searchVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:searchVC animated:NO];
}

// 初始化navbar上的按钮
- (void)initNavbarItem {
    
    //左按钮
    leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 30, 30);
//    btn2.imageEdgeInsets = UIEdgeInsetsMake(2, 0, 3, 0);
    [leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *barBtn1 = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
//    self.navigationItem.leftBarButtonItem = barBtn1;

    //右按钮
    rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
//    rightBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 38, 10, 0);
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)leftBtnClick {//消息web页
//之前原生页
//    WDXXViewController *wdxxVc = [[WDXXViewController alloc] init];
//    [self.navigationController pushViewController:wdxxVc animated:YES];
    
    if ([WShareUtil sharedData].dicSession) {

        WWebViewController *webVc = [[WWebViewController alloc] init];
        NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"wdxx",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
        NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];
        webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
        webVc.strTitle = @"我的消息";
        [self.navigationController pushViewController:webVc animated:YES];

    } else {
        [WShareUtil sharedData].Who = @"SYWDXX";
        LoginViewController *loginVc = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:loginVc animated:YES];
    }
}

- (void)rightBtnClick {
    self.tabBarController.selectedIndex = 1;
}

// 初始化scrollView上的页面
- (void)initScrollViewItem {

    if (XIPHONE) {
        _titScrollView = [[STSegmentView alloc]initWithFrame:CGRectMake(0, 90, self.view.bounds.size.width, 44)];
    } else {
        _titScrollView = [[STSegmentView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 44)];
    }
    _titScrollView.delegate = self;
    _titScrollView.titleArray = @[@"热门",@"问吧",@"学堂",@"说税"];
    _titScrollView.titleSpacing = 0;
    _titScrollView.labelFont = [UIFont systemFontOfSize:16];
    _titScrollView.bottomLabelTextColor = [UIColor blackColor];
    _titScrollView.topLabelTextColor = [UIColor redColor];
    _titScrollView.selectedBackgroundColor = [UIColor whiteColor];
    _titScrollView.selectedBgViewCornerRadius = 20;
    _titScrollView.sliderHeight = 3;
    _titScrollView.sliderColor = [UIColor redColor];

    _titScrollView.sliderTopMargin = 0;

    _titScrollView.duration = 0.3;

    UILabel *lineLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 43, WSCREENH_WIDTH, 1)];
    lineLb.backgroundColor = [UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1];
    [_titScrollView addSubview:lineLb];
    [self.view addSubview:_titScrollView];

    CGFloat tableViewW = self.view.width;
    CGFloat tableViewH = self.view.height - CGRectGetMaxY(_titScrollView.frame) - 49;

    _homeScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_titScrollView.frame), tableViewW, tableViewH)];
    _homeScrollView.delegate = self;
    _homeScrollView.backgroundColor = [UIColor clearColor];
    _homeScrollView.contentSize = CGSizeMake(tableViewW * 4, tableViewH);
    _homeScrollView.pagingEnabled = YES;
    _homeScrollView.bounces = NO;
    [self.view addSubview:_homeScrollView];

    NSArray *color = @[[UIColor greenColor],[UIColor yellowColor],[UIColor brownColor],[UIColor purpleColor],[UIColor redColor]];
    for (int i = 0; i < self.childViewControllers.count; i++) {
        UIViewController *vc = self.childViewControllers[i];
        vc.view.frame = CGRectMake(i * tableViewW, 0, tableViewW, tableViewH);
        vc.view.backgroundColor = color[i];
        [_homeScrollView addSubview:vc.view];
    }
    _titScrollView.outScrollView = _homeScrollView;
}

-(void)SYWDXXNOTICE {
    WWebViewController *webVc = [[WWebViewController alloc] init];
    NSDictionary *parametersDict = @{@"mode":@"web",@"service":@"wdxx",@"content":@{@"username":[WShareUtil sharedData].dicSession[@"nsrsbh"]}};
//    NSString *strUrl = @"http://www.sx95113.com/zstapp?params=";
//    [WShareUtil getServerURL:nil]
//    @"http://www.icdes.cn/zstapp"
    NSString *strUrl = [NSString stringWithFormat:@"%@?params=",[WShareUtil getServerURL:nil]];

    webVc.strUrl = [WShareUtil webUrlAppendingString:strUrl dic:parametersDict];
    webVc.strTitle = @"我的消息";
    [self.navigationController pushViewController:webVc animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"";

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SYWDXXNOTICE) name:@"SYWDXX" object:nil];
    
    _strId = [NSString string];
    _strKhdupsj = [NSString string];
    _strUpsj = [NSString string];
    
    [self initNavbarItem];
    
    NewHotViewController *hotViewController = [[NewHotViewController alloc]init];
    hotViewController.delegate = self;
    [self addChildViewController:hotViewController];

    HAnswerViewController *answerVc = [[HAnswerViewController alloc]init];
    [self addChildViewController:answerVc];

    SchoolViewController *schoolViewController = [[SchoolViewController alloc]init];
    [self addChildViewController:schoolViewController];

    SpokenViewController *spokenViewController =[[SpokenViewController alloc]init];
    [self addChildViewController:spokenViewController];

//    ReportViewController *reportViewController = [[ReportViewController alloc]init];
//    [self addChildViewController:reportViewController];
//
//    InvoiceViewController *invoiceViewController =[[InvoiceViewController alloc]init];
//    [self addChildViewController:invoiceViewController];

    [self initScrollViewItem];
    
    // 显示新功能提示覆盖层
    NSString *versionKey = @"CFBundleVersion";
    // 当前app的版本号（从Info.plist中获得）
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[versionKey];
    WLog(@"沙盒中的版本号%@",[WShareUtil sharedData].LASTVersion);
    WLog(@"Info.plist中获得版本号%@",currentVersion);
    if ([[WShareUtil sharedData].LASTVersion isEqualToString:currentVersion]) {//相等
    } else {//不相等
        [self initScreenView];
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:versionKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

}

- (void)buttonClick:(NSInteger)index {
    [_homeScrollView setContentOffset:CGPointMake(self.view.width * index, 0) animated:NO];

    [[NSNotificationCenter defaultCenter] postNotificationName:NOREFRESH object:nil];

    if (index == 0) {//热门
        [WShareUtil sharedData].strController = Hot_Controller;
        [[NSNotificationCenter defaultCenter] postNotificationName:HOME_HOT_NOTIFY object:nil];

    }else if (index == 1) { //问吧
        [WShareUtil sharedData].strController = Answer_Controller;
        [[NSNotificationCenter defaultCenter] postNotificationName:Answer_Controller object:nil];

    }else if (index == 2) {//学堂
        [WShareUtil sharedData].strController = School_Controller;
        [[NSNotificationCenter defaultCenter] postNotificationName:HOME_SCHOOL_NOTIFY object:nil];

    }else if (index == 3) {//说税
        [WShareUtil sharedData].strController = Spoken_Controller;
        [[NSNotificationCenter defaultCenter] postNotificationName:HOME_SPOKEN_NOTIFY object:nil];
    }
}

- (void)delegatChangeView:(NSInteger)index {
    [self buttonClick:index];
}

#pragma mark - 消息红点
-(void)Message {
    
    NSString *userName;
    if ([WShareUtil sharedData].dicSession) {
        userName = [WShareUtil sharedData].dicSession[@"nsrsbh"];
    } else {
        userName = @"-1";
    }
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"mine",@"content":@{@"revert":@"wdnews",@"username":userName}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};
    
    
    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];
        if(![[NSString stringWithFormat:@"%@",returnDic[@"unread"]] isEqualToString:@"0"]){//不是0的话就是有消息了（测试，之后前面加！）
            
            //            UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"有新消息了，快点击左上角查看吧！" delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
            //            [av show];
            
//            [SVProgressHUD showImage:nil status:@"有新消息了，快点击右上角查看吧！"];
//            [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, WSCREENH_HEIGHT *0.5 - 70)];
//            [SVProgressHUD dismissWithDelay:2.];
//            [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:0.9 green:0.91 blue:0.93 alpha:1]];   //背景颜色
            
            //召唤主线程改变UI
//            [self performSelectorOnMainThread:@selector(ChangeIcon) withObject:nil waitUntilDone:YES];
            
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(ChangeIcon) userInfo:nil repeats:NO];

        }else {
            
            //召唤主线程改变UI
//            [self performSelectorOnMainThread:@selector(SetIcon) withObject:nil waitUntilDone:YES];
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(SetIcon) userInfo:nil repeats:NO];

        }
        
    } failure:^(NSError *error) {
        WLog(@"失败");
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(SetIcon) userInfo:nil repeats:NO];
    } showProgress:NO];
}


#pragma mark - 一键检测网络请求
- (void)YJJCDataRequest {
    /*
     mode:native,service:init,content:{screen:server}
     */
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"init",@"content":@{@"screen":@"server"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};

    WLog(@"%@=======+++++",[WShareUtil getServerURL:nil]);

    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];

        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];
        
        [WShareUtil sharedData].DicState = (NSMutableDictionary *)returnDic; //服务器状态保存到全局单例
        
        //请求成功先给参数赋值，再调分享接口
        _strId = returnDic[@"id"];
        _strKhdupsj = returnDic[@"khdupsj"];
        _strUpsj = returnDic[@"upsj"];

        [self SERVERSTATESHARING];//调用服务器状态分享接口
        
        if([returnDic[@"status"] isEqualToString:@"0"]){
            
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionA) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"1"]){
            
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionB) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"2"]){
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionC) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"3"]){
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionD) userInfo:nil repeats:NO];
            
        }else if([returnDic[@"status"] isEqualToString:@"4"]){
            [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionE) userInfo:nil repeats:NO];
        }
        
    } failure:^(NSError *error) {
        WLog(@"失败");
        //检测失败清空单例字典
        [WShareUtil sharedData].DicState = nil;
        
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionE) userInfo:nil repeats:NO];

    } showProgress:NO];
}

- (void)timerActionA {//开票、申报服务器正常
    
    [dataView removeFromSuperview];
    
    [rightBtn setImage:[UIImage imageNamed:@"nav_right1"] forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self setRightBtn];

}
- (void)timerActionB {//开票服务器异常,申报服务器正常
    
    [dataView removeFromSuperview];

    [rightBtn setImage:[UIImage imageNamed:@"nav_right2"] forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self setRightBtn];

}
- (void)timerActionC {//申报服务器异常,开票服务器正常
    
    [dataView removeFromSuperview];
    
    [rightBtn setImage:[UIImage imageNamed:@"nav_right3"] forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self setRightBtn];

}
- (void)timerActionD {//开票、申报服务器异常
    [dataView removeFromSuperview];
    [rightBtn setImage:[UIImage imageNamed:@"nav_right4"] forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self setRightBtn];

}

- (void)timerActionE {//获取失败
    
    [dataView removeFromSuperview];
    
    [rightBtn setImage:[UIImage imageNamed:@"nav_right5"] forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [self setRightBtn];

}

- (void)SetIcon {//初始消息图标
    
    [leftBtn setImage:[UIImage imageNamed:@"nav_left_no"] forState:UIControlStateNormal];
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    [self setRightBtn];
}

- (void)ChangeIcon {//改变消息图标
    
    [leftBtn setImage:[UIImage imageNamed:@"nav_left_yes"] forState:UIControlStateNormal];
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    [self setRightBtn];

}

#pragma mark - 服务器状态分享接口
- (void)SERVERSTATESHARING{
    
    if ([WShareUtil strNilOrEmpty:_strId]) {
        _strId = @"";
    }
    if ([WShareUtil strNilOrEmpty:_strId]) {
        _strKhdupsj = @"";
    }
    if ([WShareUtil strNilOrEmpty:_strId]) {
        _strUpsj = @"";
    }
    
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"shareinfo",@"content":@{@"id":_strId,@"timer":_strKhdupsj,@"nowtime":_strUpsj,@"type":@"server"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};
    
    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];

        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];

        // 服务状态分享所需的字段
        [WShareUtil sharedData].shareTITLE = [returnDic objectForKey:@"title"];//分享标题
        [WShareUtil sharedData].shareSUMMARY = [returnDic objectForKey:@"summary"];//分享概要
        [WShareUtil sharedData].shareLINK = [returnDic objectForKey:@"link"];//分享地址
        [WShareUtil sharedData].shareIMG = [returnDic objectForKey:@"img"];//分享图片
        
    } failure:^(NSError *error) {
        WLog(@"失败");
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerActionE) userInfo:nil repeats:NO];
        
    } showProgress:NO];
}


- (void)setRightBtn {
    
    self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc] initWithCustomView:rightBtn],[[UIBarButtonItem alloc] initWithCustomView:leftBtn]];
}

-(void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [NavimgView removeFromSuperview];
    [NavSearchView removeFromSuperview];
}

// 初始化全屏覆盖
- (void)initScreenView {
    
    ScreenView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT)];
    ScreenView.backgroundColor = [UIColor colorWithRed:0.03 green:0.03 blue:0.04 alpha:0.7];
    
    UIImageView *imgV1 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xgnts_1"]];
    imgV1.frame = CGRectMake(WSCREENH_WIDTH - 210,20,200, 102);
    [ScreenView addSubview:imgV1];
    
    UIImageView *imgV2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"xgnts_2"]];
    imgV2.frame = CGRectMake(WSCREENH_WIDTH/2-65,WSCREENH_HEIGHT/2 - 45,130, 88);
    [ScreenView addSubview:imgV2];
    
    UIButton *OKBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    OKBtn.frame = CGRectMake(WSCREENH_WIDTH/2-50, WSCREENH_HEIGHT - 110, 100, 30);
    [OKBtn setBackgroundImage:[UIImage imageNamed:@"xgnts_3"] forState:UIControlStateNormal];
//    [OKBtn addTarget:self action:@selector(OKBtn) forControlEvents:UIControlEventTouchUpInside];
    [ScreenView addSubview:OKBtn];
    
    //全面覆盖的Btn
    UIButton *BigOKBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    BigOKBtn.frame = CGRectMake(0, 0, WSCREENH_WIDTH, WSCREENH_HEIGHT);
    [BigOKBtn setBackgroundColor:[UIColor clearColor]];
    [BigOKBtn addTarget:self action:@selector(OKBtn) forControlEvents:UIControlEventTouchUpInside];
    [ScreenView addSubview:BigOKBtn];

    [[[UIApplication sharedApplication] delegate].window addSubview:ScreenView];

}

- (void)OKBtn {
    [ScreenView removeFromSuperview];
}

#pragma mark - 热门搜索数据
- (void)SearchVCDataRequest {
    //mode:native,service:fwwb,content:{revert:hot}
    NSDictionary *parametersDict = @{@"mode":@"native",@"service":@"fwwb",@"content":@{@"revert":@"hot"}};
    NSString *secret = [NSString stringWithFormat:@"%@",[WHttpTool convertToJsonData:parametersDict]];
    //    NSDictionary *paramsDic = @{@"params":[CommonFunc encryptWithText:secret]};

    [WHttpTool POST:[WShareUtil getServerURL:nil] parameters:@{@"params":[CommonFunc encryptWithText:secret]} success:^(id responseObject) {
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *JsonDic = [WHttpTool dictionaryWithJsonString:responseStr];
        NSString *messageStr = [JsonDic objectForKey:@"message"];
        NSString *successStr = [JsonDic objectForKey:@"success"];
        // 解密请求回的数据（字典）
        NSString *returnStr = [CommonFunc decryptWithText:messageStr];
        
        // json字符串转字典
        NSDictionary *returnDic = [WHttpTool dictionaryWithJsonString:returnStr];
        NSArray *returnArr = returnDic[@"hot"];

        WLog(@"返回数组%@",returnArr);

        for (int i = 0; i < returnArr.count; i++) {
            [self.hotArray addObject:returnDic[@"hot"][i][@"title"]];
        }

        if (self.hotArray.count >=2) {
            NavSearchLb.text = [NSString stringWithFormat:@"%@  |  %@",self.hotArray[0],self.hotArray[1]];
        }

    } failure:^(NSError *error) {
        WLog(@"失败");
    } showProgress:YES];

}

- (void)dealloc{
    //移除所有通知监控
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
